package io.rainforest.rss.web.rssfollow;

import com.alibaba.cola.dto.SingleResponse;
import io.rainforest.rss.base.request.R;
import io.rainforest.rss.client.vo.follow.RssFollowReq;
import io.rainforest.rss.dao.po.RssFollow;
import io.rainforest.rss.service.rssfollow.FollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "Rss订阅")
@RequestMapping("/v1/follow/")
@Slf4j
public class FollowController {

    @Autowired
    private FollowService followService;

    @PostMapping("add")
    @ApiOperation("增加一个订阅")
    public R add(@RequestBody @Validated RssFollowReq req){
        followService.addFollow(req);
        return R.ok();
    }

    @PostMapping("query")
    @ApiOperation("查询订阅列表")
    public R query(@RequestBody RssFollowReq req){
        List<RssFollow> rssFollows = followService.queryList(req);
        return R.ok(rssFollows);
    }
    @PostMapping("editFollow")
    @ApiOperation("更新Rss订阅")
    public R editFollow(@RequestBody @Validated RssFollow req){
        followService.updateFollow(req);
        return R.ok();
    }

    @PostMapping("delFollow")
    @ApiOperation("删除Rss订阅")
    public R delFollow(String rssId){
        followService.deleteFollow(rssId);
        return R.ok();
    }

}
